package cn.likun.kit.file.bean;

import java.io.File;
import java.io.Serializable;
import java.util.Date;

import cn.likun.kit.file.FileCommons;

public class FileBean implements Serializable ,Cloneable {
	
	private static final long serialVersionUID = 4381636114791045272L;
	
	private String path;
	private String folder;
	private String name;
	private String type;
	private Long size;
	private Date lastModified;
	private Boolean isFolder = false;
	private Boolean isHidden = false;
	
	protected FileBean() {}

	public FileBean(File file) {
		String path = file.getPath();
		this.setPath(path);
		String folder = file.getParent();
		this.setFolder(folder);
		String name = file.getName();
		this.setName(name);
		Long size = file.length();
		this.setSize(size);
		Date lastModified = new Date(file.lastModified());
		this.setLastModified(lastModified);
		Boolean isFolder = file.isDirectory();
		this.setIsFolder(isFolder);
		String type = null;
		if (!isFolder) {
			type = FileCommons.getSuffixName(name);
		}
		this.setType(type);
		Boolean isHidden = file.isHidden();
		this.setIsHidden(isHidden);
	}
	
	protected void setPath(String path) {
		this.path = path;
	}

	protected void setFolder(String folder) {
		this.folder = folder;
	}

	protected void setName(String name) {
		this.name = name;
	}

	protected void setType(String type) {
		this.type = type;
	}

	protected void setSize(Long size) {
		this.size = size;
	}

	protected void setLastModified(Date lastModified) {
		this.lastModified = lastModified;
	}

	protected void setIsFolder(Boolean isFolder) {
		this.isFolder = isFolder;
	}

	protected void setIsHidden(Boolean isHidden) {
		this.isHidden = isHidden;
	}

	public String getPath() {
		return path;
	}
	public String getFolder() {
		return folder;
	}
	public String getName() {
		return name;
	}
	public String getType() {
		return type;
	}
	public Long getSize() {
		return size;
	}
	public Date getLastModified() {
		return lastModified;
	}
	public Boolean getIsFolder() {
		return isFolder;
	}
	public Boolean getIsHidden() {
		return isHidden;
	}

	@Override
	public FileBean clone() throws CloneNotSupportedException {
		return (FileBean)super.clone();
	}
	
	@Override
	public String toString() {
		return "FileBean [path=" + path + ", folder=" + folder + ", name="
				+ name + ", type=" + type + ", size=" + size
				+ ", lastModified=" + lastModified + ", isFolder=" + isFolder
				+ ", isHidden=" + isHidden + "]";
	}

}
